//
//  SHPTabBarController.swift
//  weibo
//
//  Created by songhuipan on 16/4/16.
//  Copyright © 2016年 songhuipan. All rights reserved.
//

import UIKit

class SHPTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // 初始化一个SHPTabBar
        let tabBar = SHPTabBar()
        
        tabBar.SHPDelegate = self
        
        setValue(tabBar, forKey: "tabBar")
    
        addChildrenViewControllers()

    }
    
}

// MARK: - 设置界面,遵守代理协议，实现代理方法
 extension SHPTabBarController: SHPTabBarDelegate {
        
        private func addChildrenViewControllers() {
            
            addChildrenViewController(SHPHomeTableViewController(), title: "首页", image: "tabbar_home")
            
            addChildrenViewController(SHPMessageTableViewController(), title: "消息", image: "tabbar_message_center")
            
            
            
            addChildrenViewController(SHPDiscoverTableViewController(), title: "发现", image: "tabbar_discover")
            
            addChildrenViewController(SHPProfileViewController(), title: "我的", image: "tabbar_profile")
            
            
        }
        
        // 添加子控制器的方法
        private func addChildrenViewController(vc:UIViewController,title:String,image:String) {
            
            // 设置标题是由内至外设置的
            vc.title = title
            
            vc.tabBarItem.image = UIImage(named: image)
            
            vc.tabBarItem.selectedImage = UIImage(named: "\(image)_selected")
            
    
            let nav = UINavigationController(rootViewController: vc)
            
            addChildViewController(nav)
        }
/// 中间撰写按钮点击方法
    func composeButtonClick() {
        
        presentViewController(UINavigationController(rootViewController:SHPComposeViewController()), animated: true, completion: nil)
        
    }
}

